package cn.edu.cdu.health.config;

import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class PermissionConfig {

    // 定义各角色可访问的功能
    private static final Map<String, List<String>> ROLE_PERMISSIONS = new HashMap<>();

    static {
        // 管理员权限 - 所有功能
        ROLE_PERMISSIONS.put("admin", Arrays.asList(
                "dashboard", "user-management", "Department", "appointment-management", "diagnosis", "medicine", "AiChat"
        ));

        // 医生权限 - 患者管理相关功能
        ROLE_PERMISSIONS.put("doctor", Arrays.asList(
                "dashboard", "appointment-management", "diagnosis", "AiChat"
        ));

        // 患者权限 - 仅AI聊天和个人信息
        ROLE_PERMISSIONS.put("patient", Arrays.asList(
                "dashboard", "AiChat"
        ));
    }

    public static List<String> getPermissionsByRole(String role) {
        return ROLE_PERMISSIONS.getOrDefault(role, Collections.emptyList());
    }

    public static boolean hasPermission(String role, String menuKey) {
        List<String> permissions = ROLE_PERMISSIONS.get(role);
        return permissions != null && permissions.contains(menuKey);
    }
}